{% extends 'public/layout.html' %}
{% load group_tag %}

{% block load_css %}
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/css/plugins/ladda/ladda-themeless.min.css" rel="stylesheet">
    <style>
        .float-e-margins .btn {
            margin-bottom: 0px;
        }
    </style>
{% endblock %}

{% block mbx %}
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-10">
            <h2></h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{% url 'index' %}">仪表盘</a>
                </li>

                <li>
                    <a>报警中心</a>
                </li>


                <li class="active">
                    <strong>报警自愈历史</strong>
                </li>

            </ol>
        </div>
        <div class="col-sm-2">
        </div>
    </div>
{% endblock %}

{% block body %}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>报警自愈历史</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" style="overflow:scroll;white-space : nowrap">
                        <table class="table table-striped table-bordered table-hover  dataTable no-footer">
                            <thead>
                            <tr>
                                <th class="text-center">#</th>
                                <th class="text-center">告警项目</th>
                                <th class="text-center">类型</th>
                                <th class="text-center">状态</th>
                                <th class="text-center">更新时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for ob in obj %}
                                <tr>
                                    <td class="text-center">{{ forloop.counter }}</td>
                                    <td class="text-center">{{ ob.item }}</td>

                                     {% for type_tuple in type_list %}
                                        {% if ob.type == type_tuple.0  %}
                                            <td class="text-center">{{ type_tuple.1 }}</td>
                                        {% endif %}
                                    {% endfor %}

                                    <td class="text-center">{% if ob.status %}
                                        <dd><span class="label label-primary">告警正常</span></dd>
                                    {% else %}
                                        <dd><span class="label label-danger">发生告警</span></dd>
                                    {% endif %}</td>

                                    <td class="text-center">{{ ob.alertime|date:"Y-m-d H:i:s" }}</td>

                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>

                        <div class="row">
                            <center>
                                <div class="btn-group">
                                    <a class="btn btn-white" href="{% url 'auto_recovery' %}?page=1">首页</a>
                                    {% if page_obj.has_previous %}
                                        <a class="btn btn-white" type="button"
                                           href="?page={{ page_obj.previous_page_number }}">
                                            上一页
                                        </a>
                                    {% else %}
                                        <a class="btn btn-white" type="button" disabled="disabled">上一页</a>
                                    {% endif %}

                                    {% for page in page_range %}
                                        {% ifequal page page_obj.number %}
                                            <a class="btn btn-white active">{{ page }}</a>
                                        {% else %}
                                            <a href="?page={{ page }}" class="btn btn-white">{{ page }}</a>
                                        {% endifequal %}
                                    {% endfor %}

                                    {% if page_obj.has_next %}
                                        <a class="btn btn-white" type="button"
                                           href="?page={{ page_obj.next_page_number }}">
                                            下一页
                                        </a>
                                    {% else %}
                                        <a class="btn btn-white" type="button" disabled>下一页</a>
                                    {% endif %}
                                    <a class="btn btn-white"
                                       href="{% url 'auto_recovery' %}?page={{ paginator.num_pages }}">末页</a>
                                </div>
                            </center>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block load_js %}
    <script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="/static/js/plugins/ladda/spin.min.js"></script>
    <script src="/static/js/plugins/ladda/ladda.min.js"></script>
    <script src="/static/js/plugins/ladda/ladda.jquery.min.js"></script>

    <!-- Toastr script -->
    <script src="/static/js/plugins/toastr/toastr.min.js"></script>
    <script>
        $('#submit_host').click(function () {
            var btn = $(this).ladda();
            btn.ladda('start');
            var data = $('#create_host_form').serialize();
            $.ajax({
                url: '{% url 'monitor_config' %}',
                type: 'post',
                data: data,
                success: function (res) {
                    setTimeout(function () {
                        btn.ladda('stop');
                    }, 200);
                    if (res.status == 0) {
                        swal({
                            title: res.msg,
                            type: 'success',
                            confirmButtonText: "OK"
                        }, function () {
                            window.location.href = '{% url 'monitor_config' %}';
                        });
                    } else {
                        swal({
                            title: res.msg,
                            type: 'error',
                            confirmButtonText: "知道了"
                        });
                    }
                }
            })

        })


        function showfunc(value) {
            var selectedOption=value.options[value.selectedIndex];
                //alert(selectedOption);

                if(selectedOption.value=="0"){
                    var sHtml = '';
                    sHtml += '<div class="form-group"> \
                                <label class="col-md-12 control-label">监控地址url</label> \
                                <input type="text" class="form-control" placeholder="监控地址url" \
                                       name="url"> \
                            </div>';
                    document.getElementById("monitor_content").innerHTML = sHtml;
                }

                if (selectedOption.value=="1"){
                    var sHtml = '';
                    sHtml += '<div class="form-group"> \
                                <label class="col-md-12 control-label">监控地址</label> \
                                <input type="text" class="form-control" placeholder="请输入监控地址（IP或者域名)" \
                                       name="address"> \
                            </div> \
                            <div class="form-group"> \
                                <label class="col-md-12 control-label">监控端口</label> \
                                <input type="text" class="form-control" placeholder="监控端口" \
                                       name="port"> \
                            </div>';

                    document.getElementById("monitor_content").innerHTML = sHtml;
                }

        }



    </script>
{% endblock %}